package com.example.netty.channel.handler;

import java.nio.charset.Charset;
import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 解码器
 * 将ByteBuf转为Object
 */
public class MyDecoder extends ByteToMessageDecoder {
    private static final Logger logger = LoggerFactory.getLogger(MyDecoder.class);

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out)
        throws Exception {
        logger.info("最大容量："+in.capacity());
        out.add(in.toString(Charset.defaultCharset()));
    }
}
